﻿using System.Collections.Generic;
using Brjnk.CoordinateSystem2D;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Coordinate2DTest
{
    [TestClass()]
    public class LinearAxisTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes

        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion Additional test attributes

        [TestMethod()]
        public void GetAxisLabelsTest()
        {
            LinearAxis target = new LinearAxis();

            double from = 0F;
            double to = 1F;
            double minSpacing = 1F;

            var actual = target.GetAxisLabels(from, to, minSpacing);

            List<LabelInfo> output = new List<LabelInfo>();
            LabelInfo[] values = { new LabelInfo(LabelSize.Large, 0, 0.ToString()),
                                 new LabelInfo(LabelSize.Small, 0.1, null),
                                 new LabelInfo(LabelSize.Small, 0.2, null),
                                 new LabelInfo(LabelSize.Small, 0.3, null),
                                 new LabelInfo(LabelSize.Small, 0.4, null),
                                 new LabelInfo(LabelSize.Medium, 0.5,null),
                                 new LabelInfo(LabelSize.Small, 0.6, null),
                                 new LabelInfo(LabelSize.Small, 0.7, null),
                                 new LabelInfo(LabelSize.Small, 0.8, null),
                                 new LabelInfo(LabelSize.Small, 0.9, null),
                                 new LabelInfo(LabelSize.Big, 1.0, 1.0.ToString())};
            TestLabels(actual.Labels, values, 0, 1);
        }

        [TestMethod()]
        public void GetAxisLabelsTest2()
        {
            LinearAxis target = new LinearAxis();
            target.SpacingBase = 3;

            double from = -4F;
            double to = -1F;
            double minSpacing = 1.1F;

            var actual = target.GetAxisLabels(from, to, minSpacing);

            List<LabelInfo> output = new List<LabelInfo>();
            LabelInfo[] values = {new LabelInfo(LabelSize.Medium, -4,null),
                                 new LabelInfo(LabelSize.Big, -3,(-3).ToString()),
                                 new LabelInfo(LabelSize.Medium, -2, null),
                                 new LabelInfo(LabelSize.Medium, -1, null)};

            TestLabels(actual.Labels, values, -4, -1);
        }

        [TestMethod()]
        public void GetAxisLabelsTest3()
        {
            LinearAxis target = new LinearAxis();
            target.SpacingBase = 10;
            target.Reverse = true;

            double from = -1F;
            double to = 103F;
            double minSpacing = 11F;

            var actual = target.GetAxisLabels(from, to, minSpacing);

            List<LabelInfo> output = new List<LabelInfo>();
            LabelInfo[] values = { new LabelInfo(LabelSize.Large, 00,(0).ToString()),
                                 new LabelInfo(LabelSize.Small, 10,null),
                                 new LabelInfo(LabelSize.Small, 20,null),
                                 new LabelInfo(LabelSize.Small, 30,null),
                                 new LabelInfo(LabelSize.Small, 40,null),
                                 new LabelInfo(LabelSize.Medium, 50,null),
                                 new LabelInfo(LabelSize.Small, 60,null),
                                 new LabelInfo(LabelSize.Small, 70,null),
                                 new LabelInfo(LabelSize.Small, 80,null),
                                 new LabelInfo(LabelSize.Small, 90,null),
                                 new LabelInfo(LabelSize.Big, 100, (-100).ToString())};

            TestLabels(actual.Labels, values, -1, 103);
        }

        private static void TestLabels(IEnumerable<LabelInfo> labels, LabelInfo[] requiredValues, double min, double max)
        {
            int i = 0;
            double last = double.MinValue;
            foreach (var label in labels)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0} {1} {2}", label.Size, label.Value, label.Text));
                if (label.Value < last) Assert.Fail("Hodnoty musí být vraceny od nejmenší k největší");
                last = label.Value;
                //if (label.Value < min) continue;
                //if (label.Value > max) continue;

                Assert.AreEqual(requiredValues[i].Size, label.Size);
                Assert.AreEqual(requiredValues[i].Text, label.Text);
                Assert.AreEqual(requiredValues[i].Value, label.Value, 0.000001, i.ToString());
                i++;
            }
            Assert.AreEqual(requiredValues.Length, i);
        }
    }
}